package com.gdpu.controller;

import com.gdpu.api.CommonPage;
import com.gdpu.api.CommonResult;
import com.gdpu.dto.OmsQueryParamDto;
import com.gdpu.service.OmsOrderService;
import com.gdpu.vo.OmsOrderDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @Author:weiming
 * @Date:2021/5/14
 * 订单模块
 */
@Api(tags = "订单模块")
@RequestMapping("/orders")
@RestController
public class OmsOrderController {

    @Autowired
    private OmsOrderService omsOrderService;

    @ApiOperation("获取全部订单")
    @GetMapping("/")
    public CommonResult getAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                                     @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize,
                                     OmsQueryParamDto omsQueryParamDto){
        CommonPage commonPage = omsOrderService.list(pageNum,pageSize,omsQueryParamDto);
        return CommonResult.success(commonPage);
    }

    @ApiOperation("获取订单详情")
    @GetMapping("/{orderId}")
    public CommonResult getDetail(@PathVariable(name = "orderId") Integer orderId){
        OmsOrderDetailVo omsOrderDetailVo = omsOrderService.get(orderId);
        HashMap<Object, Object> map = new HashMap<>(1);
        map.put("omsOrderDetail",omsOrderDetailVo);
        return CommonResult.success(map);
    }

    @ApiOperation("商品发货")
    @PostMapping("/delivery/")
    public CommonResult delivery(@RequestParam(name = "orderId") Integer orderId){
        int result = omsOrderService.delivery(orderId);
        return CommonResult.failed();
    }

}
